$(function () {
    layui.use('form', function(){
        var form = layui.form;
    });
    selectCodeType("sex");
    selectCodeType("education");
    selectCodeType("personnelType");
    selectAllPersonnel();
})
function selectAllPersonnel() {
    let pageUtil ={
        pageSize:$("#pageSize").val(),
        pageNumber:$("#pageNumber").val()
    }
    let data1 = {
        name:$("#personnelName").val(),
        personnelType:$("#personnelType").val(),
        sex:$("#sex").val(),
        education:$("#education").val(),
        pageUtil:pageUtil,
    }
    let data = myAjax("/personnel/selectAllPersonnel",data1,"post");
    let list = data.list;
    $("#count").html(data.count);
    let count = $("#count").text();
    let pageSize = $("#pageSize").val();
    let a = Math.ceil(count/pageSize);
    $("#pageCount").html(a);
    //页数 改变 上一页下一页颜色=================================================================
    let pageNumber= $("#pageNumber").val();
    if (pageNumber<=1){
        $("#lastPage").attr('disabled',"true");
        $("#lastPage").css("background-color","silver");
        $("#nextPage").removeAttr("disabled");
        $("#nextPage").removeAttr('style',"");

    }else if (pageNumber==a){
        $("#nextPage").attr('disabled',"true");
        $("#lastPage").removeAttr("disabled");
        $("#nextPage").css("background-color","silver");
        $("#lastPage").removeAttr('style',"");
    }
    let html ='';
    for (let i = 0 ;i<list.length;i++){
        let personnelGroup = list[i].personnelGroup;
        let personnelType = list[i].personnelType;
        let sex = list[i].sex;
        let education = list[i].education;
        if (personnelGroup==null){
            personnelGroup = '';
        }
        //类型
        if (personnelType=='student'){
            personnelType = '学生';
        }else if(personnelType=='coach'){
            personnelType = '教练';
        }else{
            personnelType = '班主任';
        }
        //男女
        if (sex=='male'){
            sex = '男';
        }else {
            sex = '女';
        }
        //学历
        if (education=='ben'){
            education = '本科';
        }else if(education=='zhuan'){
            education = '专科';
        }else{
            education = '硕士';
        }
        html+='<tr>' +
            '<td>'+list[i].id+'</td>\n' +
            '<td>'+list[i].personnelNumber+'</td>\n' +
            '            <td>'+personnelType+'</td>\n' +
            '            <td>'+personnelGroup+'</td>\n' +
            '            <td>'+list[i].name+'</td>\n' +
            '            <td>'+sex+'</td>\n' +
            '            <td>'+list[i].age+'</td>\n' +
            '            <td>'+education+'</td>\n' +
            '            <td>'+list[i].graduateSchool+'</td>\n' +
            '            <td>'+list[i].nativeplace+'</td>\n' +
            '            <td>'+list[i].location+'</td>\n' +
            '            <td>'+list[i].phone+'</td>\n' +
            '            <td>'+list[i].urgentphone+'</td>\n' +
            '            <td><a href="javascript:edit('+list[i].id+')" style="color: #1E9FFF">编辑</a>&nbsp;&nbsp;\n' +
            '                <a href="" style="color: red">删除</a></td>\n'+
            '</tr>'
    }
    $("#personnelManage").html(html);
}
function edit(i) {
    localStorage.setItem("personnelId",i)
    $("#body").load("personnelUpdate.html");
}
//分页查找=================================================
function firstPage() {
    $("#pageNumber").val(1);
    $("#nextPage").removeAttr('style',"");
    selectAllPersonnel();
}
function lastPage() {
    let a = parseInt($("#pageNumber").val());
    if (a>1){
        $("#pageNumber").val(($("#pageNumber").val()-1));
        $("#nextPage").removeAttr('style',"");
    }
    selectAllPersonnel();
}
function nextPage() {
    let a = parseInt($("#pageNumber").val());
    let count = $("#count").text();
    let pageSize = $("#pageSize").val();
    let b = Math.ceil(count/pageSize);
    if (a<b){
        $("#lastPage").removeAttr('style',"");
        $("#pageNumber").val(a+1);
    }
    selectAllPersonnel();
}
function changes() {
    let a = parseInt($("#pageNumber").val());
    let count = $("#count").text();
    let pageSize = $("#pageSize").val();
    let b = Math.ceil(count/pageSize);
    if (a<=1){
        $("#pageNumber").val(1);
        $("#lastPage").attr('disabled',"true");
    }else if (a>=b){
        $("#pageNumber").val(b);
        $("#nextPage").attr('disabled',"true");
    }else {
        $("#lastPage").removeAttr("disabled");
    }
}
function endPage() {
    let count = $("#count").text();
    let pageSize = $("#pageSize").val();
    let a = Math.ceil(count/pageSize);
    $("#pageNumber").val(a);
    $("#lastPage").removeAttr('style',"");
    selectAllPersonnel();
}
